package com.tianhui.consignortwofei.mvp.ui.activity;

import android.os.Bundle;
import android.text.TextUtils;

import androidx.recyclerview.widget.RecyclerView;

import com.fgs.common.CommonFragment;
import com.fgs.common.CommonPresenter;
import com.fgs.common.CommonResponse;
import com.fgs.common.CommonView;
import com.fgs.common.progress.ExceptionHandle;
import com.fgs.common.progress.ObserverResponseListener;
import com.fgs.common.utils.LogUtil;
import com.fgs.common.widget.itemView.InputItemView;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.constant.KeyValue;
import com.tianhui.consignortwofei.manager.SharedPreferenceManager;
import com.tianhui.consignortwofei.mvp.model.FeedBackModel;
import com.tianhui.consignortwofei.mvp.model.enty.FeedBackInfo;
import com.tianhui.consignortwofei.mvp.model.enty.OrderInfo;
import com.tianhui.consignortwofei.mvp.model.enty.evaluation.EvaluationInfo;
import com.xuexiang.xui.widget.edittext.MultiLineEditText;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author fgs
 * @date 2020/4/30
 * @description
 **/
public class DriverFeedBackActivity extends UploadPictureActivity {
    @BindView(R.id.activity_feed_back_suggestEditText)
    MultiLineEditText mSuggestEditText;
    @BindView(R.id.activity_feed_back_contractInputItemView)
    InputItemView mContractInputItemView;
    @BindView(R.id.activity_feed_back_recyclerView)
    RecyclerView mRecyclerView;


    private FeedBackModel mModel;
    private FeedBackInfo mInfo;
    private EvaluationInfo mEvaluationInfo;

    @Override
    public int getLayoutId() {
        return R.layout.activity_feed_back;
    }

    @Override
    public CommonPresenter createPresenter() {
        return null;
    }

    @Override
    public CommonView createView() {
        return null;
    }

    @Override
    public String getToolbarTitle() {
        return "投诉建议";
    }

    @Override
    public void init() {
        super.init();
    }

    @Override
    public RecyclerView getPictureRecyclerView() {
        return mRecyclerView;
    }

    @Override
    public String getPictureModule() {
        return "feedback";
    }

    @Override
    public CommonFragment createFragment() {
        return null;
    }


    @OnClick(R.id.activity_feed_back_commitButton)
    public void commit() {

        Bundle bundle = getIntent().getExtras();
        if (null != bundle && !bundle.isEmpty()) {
            OrderInfo info = bundle.getParcelable(KeyValue.KEY_ORDER_INFO);
            mEvaluationInfo.dispatchno = info.dispatchno;
        }


        String content = mSuggestEditText.getContentText();
        String contact = mContractInputItemView.getContent();
        if (TextUtils.isEmpty(content)) {
            showToast("意见内容不能为空");
            return;
        }
        if (TextUtils.isEmpty(contact)) {
            showToast("联系方式不能为空");
            return;
        }

        if (mInfo == null) {
            mInfo = new FeedBackInfo();
        }
        mInfo.content = content;

        String selectPictureId = getSelectPictureId();
        mInfo.picture = selectPictureId;

        mInfo.terminal = "Android";
        mInfo.feedtype = "1";
        mInfo.occtype = "1";
        mInfo.driverid = SharedPreferenceManager.getInstance().getConsignorId();

        LogUtil.print(mInfo.toString());
        requestFeedBackCommit();
    }

    private void requestFeedBackCommit() {
        if (mModel == null) {
            mModel = new FeedBackModel();
        }

        mModel.feedBackCommitModel(this, mInfo, true, this.bindLifecycle(), new ObserverResponseListener<CommonResponse>() {
            @Override
            public void onNext(CommonResponse baseResponse) {
                if (baseResponse.getCode() == 20000) {
                    showToast("提交成功");
                    finish();
                } else {
                    showToast(baseResponse.getMsg());
                }
            }

            @Override
            public void onError(ExceptionHandle.ResponseThrowable e) {

                showToast(e.message);

            }
        });
    }


    @Override
    protected boolean isShowFinishTipDialog() {
        return true;
    }
}
